
LevelGunPick = Class.extend({
    init: function (context,id, imgs, audios, money, points) {
        this.context = context;
        this.id = id;
        this.images = imgs;
        this.audios = audios;
        this.money = money;
        this.points = points;
        
        
        this.gameField1 = imgs[10];
        this.gameField2 = imgs[11];
        this.gameField3 = imgs[12];
        
        this.levelAndGunImageCords = 
	    	{
	    		X:90,
	    		Y:200,
	    		width:250,
	    		height:180
	    	};
        
        
        this.minLevelTwoPoints = 1000;
        this.minLevelThreePoints = 2000;
        
        this.minLevelTwoMoney = 400;
        this.minLevelThreeMoney = 1000;
        
        this.levelOneKillingEnemies = 7;
        this.levelTwoKillingEnemies = 12;
        this.levelThreeKillingEnemies = 15;
        
        this.uziPrice = 400;
        this.ak47Price = 1000;
        
        
        this.pickLevel();
    },
    
    pickLevel : function () {
        
        var self = this;
        
        //some shadow for images
        self.context.save();
        self.context.shadowColor = '#000';
        self.context.shadowBlur = 50;
        
        //draw images for levels
        self.drawImages(self.context,
                        self.gameField1,
                        self.gameField2,
                        self.gameField3,
                        self.minLevelTwoPoints,
                        self.minLevelThreePoints,
                        self.levelAndGunImageCords,
                        self.points,
                        0,
                        0
                        )
        
        //some text
        self.context.fillStyle = "white";
        self.context.font ="60px Impact, fantasy";
        self.context.fillText("Pick Level",390,100);
        
        self.context.fillText("Level 1",135,500);
        self.context.fillText("Level 2",435,500);
        
        self.context.fillText("Level 3",735,500);           
        self.context.restore();
        
        self.context.restore();

        //do pick level
        document.onmousedown = function (e) {
            
            var mouseCordinateX = e.offsetX;
            var mouseCordinateY = e.offsetY;
            
            
            self.audios[4].load();
            self.audios[4].play();
           
            self.context.drawImage(self.images[16],
                            0, 0,
                            1024,720,
                            mouseCordinateX, mouseCordinateY,
                            75, 60);
                          
                        
            
            setTimeout(function(){
                
                if( mouseCordinateX > self.levelAndGunImageCords.X &&
                    mouseCordinateX < (self.levelAndGunImageCords.X + self.levelAndGunImageCords.width) &&
                    mouseCordinateY > self.levelAndGunImageCords.Y &&
                    mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){

                        self.context.clearRect(0,0,1024,720);
                        self.pickGun(self.gameField1,self.levelOneKillingEnemies);
                    }
                if(self.points >= self.minLevelTwoPoints){
                    if( mouseCordinateX > (self.levelAndGunImageCords.X + 300)&&
                        mouseCordinateX < (self.levelAndGunImageCords.X + 300 + self.levelAndGunImageCords.width) &&
                        mouseCordinateY > self.levelAndGunImageCords.Y &&
                        mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){

                            self.context.clearRect(0,0,1024,720);
                            self.pickGun(self.gameField2,self.levelTwoKillingEnemies);
                    }
                }
                if(self.points >= self.minLevelThreePoints){
                    if( mouseCordinateX > (self.levelAndGunImageCords.X + 600) &&
                        mouseCordinateX < (self.levelAndGunImageCords.X + 600 + self.levelAndGunImageCords.width) &&
                        mouseCordinateY > self.levelAndGunImageCords.Y &&
                        mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){

                            self.context.clearRect(0,0,1024,720);
                            self.pickGun(self.gameField3,self.levelThreeKillingEnemies);
                    }
                }
            
            },150);
        };

    },
    
    pickGun : function (level,countOfTheKillingEnemies) {
        
        this.level = level;
        var self = this;
        
        //new shadows
        self.context.save();
        self.context.shadowColor = '#FFF';
        self.context.shadowBlur = 50;
        
        //draw images for guns
        self.context.clearRect(0,0,1024,720);
        self.drawImages(self.context,
                        self.images[13],
                        self.images[14],
                        self.images[15],
                        self.minLevelTwoMoney,
                        self.minLevelThreeMoney,
                        self.levelAndGunImageCords,
                        self.money
                        )
                                
        
        //some text 
        
        self.context.fillStyle = "white";
        self.context.font ="60px Impact, fantasy";
        self.context.fillText("Pick Gun",400,100);
        
        self.context.shadowColor = '#000';
        self.context.font ="40px Impact, fantasy";
        self.context.fillText("Handgun M9",105,450);
        self.context.fillText("0$",195,175);
        
        self.context.fillText("Mini-UZI",445,450);
        self.context.fillText("400$",475,175);
        
        self.context.fillText("AK 47",775,450);
        self.context.fillText("1000$",765,175);
        self.context.shadowBlur = 0;
        
        self.context.restore();
        
        //do the game if you pick right pick
        document.onmousedown = function (e) {
            var mouseCordinateX = e.offsetX;
            var mouseCordinateY = e.offsetY;
            
            self.audios[4].load();
            self.audios[4].play();

            self.context.drawImage(self.images[16],
                            0, 0,
                            1024,720,
                            mouseCordinateX, mouseCordinateY,
                            75, 60);
                            
                setTimeout(function(){
                    

                    if( mouseCordinateX > self.levelAndGunImageCords.X &&
                        mouseCordinateX < (self.levelAndGunImageCords.X + self.levelAndGunImageCords.width) &&
                        mouseCordinateY > self.levelAndGunImageCords.Y &&
                        mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){
                            self.context.clearRect(0,0,1024,720);
                            var game = new Game(self.context,
                            					self.id,
                                                'container',
                                                self.level,
                                                self.images[7],
                                                self.images,
                                                self.audios,
                                                self.audios[0],
                                                10,
                                                self.money,
                                                self.points,
                                                countOfTheKillingEnemies);
                        }
                    
                    if(self.money >= self.minLevelTwoMoney){    
                        if( mouseCordinateX > (self.levelAndGunImageCords.X + 300)&&
                            mouseCordinateX < (self.levelAndGunImageCords.X + 300 + self.levelAndGunImageCords.width) &&
                            mouseCordinateY > self.levelAndGunImageCords.Y &&
                            mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){
                                self.context.clearRect(0,0,1024,720);
                                self.money = self.money - 400;
                                var game = new Game(self.context,
                                					self.id,
                                                    'container',
                                                    self.level,
                                                    self.images[8],
                                                    self.images,
                                                    self.audios,
                                                    self.audios[1],
                                                    20,
                                                    self.money,
                                                    self.points,
                                                    countOfTheKillingEnemies);
                            }

                    }
                    if(self.money >= self.minLevelThreeMoney){
                        if( mouseCordinateX > (self.levelAndGunImageCords.X + 600) &&
                            mouseCordinateX < (self.levelAndGunImageCords.X + 600 + self.levelAndGunImageCords.width) &&
                            mouseCordinateY > self.levelAndGunImageCords.Y &&
                            mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){
                                self.context.clearRect(0,0,1024,720);
                                self.money = self.money - 1000;

                                var game = new Game(self.context,
                                					self.id,
                                                    'container',
                                                    self.level,
                                                    self.images[9],
                                                    self.images,
                                                    self.audios,
                                                    self.audios[2],
                                                    30,
                                                    self.money,
                                                    self.points,
                                                    countOfTheKillingEnemies);
                            }
                    }
                    
            },150);
        
        };
    },
    
    drawImages : function ( context,
                            image1,
                            image2,
                            image3,
                            minParameterLevel2,
                            minParameterLevel3,
                            cords,
                            parameter,
                            uziPrice,
                            ak47Price) {
        this.context = context;
        this.image1 = image1;
        this.image2 = image2;
        this.image3 = image3;
        this.minParameterLevel2 = minParameterLevel2;
        this.minParameterLevel3 = minParameterLevel3;
        this.cords = cords;
        this.parameter = parameter;
        this.uzi = uziPrice;
        this.ak47 = ak47Price;
        
        this.context.drawImage(this.image1,
                                    0, 0,
                                    1200,568,
                                    this.cords.X, this.cords.Y,
                                    this.cords.width, this.cords.height);
        
        if(this.parameter >= this.minParameterLevel2){
            this.context.drawImage(this.image2,
                                    0, 0,
                                    1200,720,
                                    (this.cords.X +300), this.cords.Y,
                                    this.cords.width, this.cords.height);

        }else{
            this.context.drawImage(this.image2,
                                0, 0,
                                1200,720,
                                (this.cords.X +300), this.cords.Y,
                                this.cords.width, this.cords.height);
            this.context.fillStyle = "rgba(255, 255, 255, 0.5)";                 
            this.context.fillRect(  (this.cords.X +300), this.cords.Y,
                                this.cords.width, this.cords.height);
        }
        
        if(this.parameter >= this.minParameterLevel3){
            this.context.drawImage(this.image3,
                                0, 0,
                                824,520,
                                (this.cords.X + 600), this.cords.Y,
                                this.cords.width, this.cords.height);
        }else{
            this.context.drawImage(this.image3,
                                0, 0,
                                824,520,
                                (this.cords.X + 600), this.cords.Y,
                                this.cords.width, this.cords.height);
            this.context.fillStyle = "rgba(255, 255, 255, 0.5)";                 
            this.context.fillRect(  (this.cords.X + 600), this.cords.Y,
                                this.cords.width, this.cords.height);
        }
    }
        

    

});


